<template>
    <div id="member">
        <el-col :span="24" class="action-bar">
            <el-button type="primary" size="medium" @click="toGoodsEditor">添加</el-button>
        </el-col>
        

        <!-- 列表 -->
        <el-table
            :data="tableData"
            style="width: 100%">
            <el-table-column
                prop="date"
                label="封面图"
                width="100">
                <template slot-scope="scope">
                        <img :src="scope.row.thumb_url" alt="" style="width:60px;height:60px;object-fit:cover">
                </template>
            </el-table-column>
            <el-table-column
                prop="name"
                label="名称"
                width="200"
                >
            </el-table-column>
            <el-table-column
                prop="exchange_integral"
                label="所需积分"
                width="200"
                >
            </el-table-column>
            <el-table-column
                prop="sale_count"
                label="已兑换件"
                width="200"
                >
            </el-table-column>
            <el-table-column
                prop="stock"
                label="库存"
                width="200"
                >
            </el-table-column>
            <!-- <el-table-column
                prop="status_name"
                label="排序"
                width="100"
                >
            </el-table-column> -->
            <el-table-column label="上/下架" width='180'>
                <template slot-scope="scope">
                    <el-switch
                    v-model="scope.row.is_shop"
                    active-text="下架"
                    inactive-text="上架">
                    </el-switch>
                </template>
            </el-table-column>
            <el-table-column label="操作" width='280'>
                <template slot-scope="scope">
                    <el-button type='text' @click="toGoodsEditor(scope.row.id)">编辑</el-button>
                    <el-button type='text' @click="toGoodsBanner(scope.row.id)">设置banner</el-button>
                    <el-button type='text' @click="showGood(scope.row.id)">查看详情</el-button>
                    <el-button type='text' @click="deletePost(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>
            
            
        </el-table>

    </div>
</template>
<script>
export default {
    name:'member',
    data() {
        return {
            id:'',
            name:'',
            tableData: [{}],
            page:1,
            postType:'',
            postTypeOptions:[],
            totalPage:0,
                
        }
    },
    methods: {    
        showGood(id){
            //查看详情
            this.$router.push({name:'GoodsDetail',query:{id:id}})
        }, 
        toGoodsBanner(id){
            //修改banner
            this.$router.push({name:'GoodsBanner',query:{id:id}})
        }, 
        async getGoodsList(){
            //获取会员列表
            let params={
                page:this.page,
                limit:16,
            }
            let res=await this.$api.getGoodsList(
                params);
            if(res.data.level=='success'){
                this.tableData=res.data.data;
                this.totalPage=res.data.page_info.total;
            }
        },
        pageChange(e){
			//翻页
			this.page=e;
			this.getGoodsList();
        },
        async submit(){
            let params={
                circle_id:this.circleId,
                classify_id:this.postType
            }
            let res=await this.$api.adminSetCircleSupportClassify(params)
            if(res.data.level=='success'){
                this.$message({
                    type:'success',
                    message:res.data.message
                })
            }else{
                this.$message({
                    type:'error',
                    message:res.data.message
                })
                
            }
        },
        async deletePost(id){
            //删除圈子类型
             let judge=null
            try {
              judge=  await this.$confirm('删除该圈子?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
                })
            } catch (error) {
                judge='cancel'
            }
            if(judge){
                let res =await this.$api.delGoods({id:id});
                if(res.data.level=='success'){
                    this.$message({
                    type:'success',
                        message:res.data.message
                    })
                    this.getGoodsList()
                }else{
                    this.$message({
                        type:'error',
                        message:res.data.message
                    })
                    
            }
            }
            console.log(judge)
        },
        initData(){

        },
        toGoodsEditor(id){
            if(isNaN(id)){
                this.$router.push('GoodsEditor')
            }else{
                this.$router.push({name:'GoodsEditor',query:{id}})
            }
            
        },

    },
    mounted() {
        this.circleId=this.$route.query.id;
        // this.getArticleClassifyList()
        this.getGoodsList()
    },
}
</script>
<style lang="scss" scoped>
.screen{
          margin-top: -10px !important;
      }
    .action-bar{
			background-color: #f2f2f2;
			height: 60px;
			margin: 10px 0px;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			padding-left: 20px;
			.action-bar-input{
				width: 250px;
				margin-right: 14px;
      }
      .task-form-text{
				color: #666666;
			}
		}
		.el-table-style{
			width: 100%;
			border: 1px solid #f2f2f2;
		}
		.footer-bar{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #f2f2f2;
			padding: 8px;
			margin: 10px 0px;
			box-sizing: border-box;
		}
		.dialog-footer{
			text-align: center;
		}
		.executorList{
			display: flex;
			flex-wrap: wrap;
			div{
				margin:10px;
				border:1px solid #eee;
				border-radius: 5px;
				padding:5px 10px;
			}
		}
</style>